package com.zkingsoft.web.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.zkingsoft.web.bean.WebMsg;
import com.zkingsoft.web.dao.WebMsgDao;
import com.zkingsoft.web.service.WebMsgService;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-01-11 13:38
 */
@Service("webMsgService")
public class  WebMsgServiceImpl implements    WebMsgService  {

	
	@Autowired
	private WebMsgDao webMsgDao;
	
	
	@Override
	public int add(WebMsg webMsg){
		
		return webMsgDao.insert(webMsg);
		
	}
	
	@Override
	public int batchAdd(List<WebMsg>  webMsgList) {
		return webMsgDao.batchInsert(webMsgList);
	}
	
	
   	
    @Override
	public int modifyByMap(WebMsg oldWebMsg
	,WebMsg newWebMsg){
	
		try {
			if (!ModelUtils.isModified(oldWebMsg, newWebMsg)) {
				return 1;
			}
		} catch (NoSuchFieldException e1) {
			e1.printStackTrace();
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldWebMsg, newWebMsg);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("msgId", oldWebMsg.getMsgId());
			webMsgDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(WebMsg webMsg){
	
		return webMsgDao.updateByModel(webMsg);
	
	}
	
	
	
	@Override
	public int remove(List<Long> list){
	
		return webMsgDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long msgId){
	
		return webMsgDao.deleteById(msgId);
	
	}
	
	@Override
	public int removeByModel(WebMsg webMsg){
	
		return webMsgDao.deleteByModel(webMsg);
	
	}
	
	
	@Override
	public List<WebMsg> findInPage(WebMsg webMsg,  PaginationVO pageVo){
	
		return webMsgDao.selectInPage(webMsg , pageVo);
	
	}
	
	@Override
	public List<WebMsg> findByModel(WebMsg webMsg){
	
		return webMsgDao.selectByModel(webMsg);
	
	}
	
	@Override
	public int  findTotal(WebMsg webMsg){
	
		return webMsgDao.selectTotalRecord(webMsg);
	
	}
	
	@Override
	public WebMsg  findById(Long msgId){
	
		return webMsgDao.selectById(msgId);
	
	}

   	
	
	
}